package handler

import (
	"article-list/models"
	"github.com/gin-gonic/gin"
	"strconv"
)

func List(c *gin.Context) {
	var articles []models.Article
	page, _ := strconv.Atoi(c.DefaultQuery("page", "2"))
	size, _ := strconv.Atoi(c.DefaultQuery("size", "3"))
	offset := (page - 1) * size
	models.DB.Offset(offset).Limit(size).Find(&articles)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "ok",
		"data": articles,
	})
	return
}
func Detail(c *gin.Context) {
	id := c.Query("id")
	var article models.Article
	models.DB.Where("id=?", id).Find(&article)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "ok",
		"data": article,
	})
	return
}
